//
//  RootTableViewController.m
//  RSTools
//
//  Created by thinkjoy on 2017/9/12.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RootTableViewController.h"
#import "RSDeviceInfoVC.h"
#import "AES_Base64VC.h"
#import "RSImageOperationVC.h"
#import "RSSystemUtit.h"
#import "UIViewController+RSSystemUtit.h"
#import "RSSystemSettingTableVC.h"
#import "RSCameraOrLibraryVC.h"
#import "TZImagePickerControllerDemoVC.h"
#import "RSAutolayoutTextViewCellVC.h"
#import "RSTableCollectionView.h"
#import "RSSpecialFieldVC.h"
#import "RSTouchIDVC.h"
#import "RSShakeVC.h"
#import "RSShowQRCode_BarCodeVC.h"
#import "RSAboutSGQRCodeVC.h"
#import "RSCopeLabVC.h"

#import "RSRuntimeLrarnTableVC.h"
#import "RSPredicateVC.h"
#import "RSDrawDemoTableVC.h"
#import "RSViewController.h"



#import <Masonry/Masonry.h>
@interface RootTableViewController ()
{
    NSMutableArray  * _resourceDataMuAry;
}


@end

@implementation RootTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _resourceDataMuAry  =   [NSMutableArray array];
    [_resourceDataMuAry addObject:@{@"系统相关":@[@"获取系统相关设备码",
                                              @"AES128加/解密",
                                              @"打电话",
                                              @"发短信(跳转到系统短信应用中)",
                                              @"发短信(在当前APP中)",
                                              @"发邮件(跳转到系统邮件应用中)",
                                              @"发邮件(在当前APP中)",
                                              @"系统设置界面",
                                              ]}];
    [_resourceDataMuAry addObject:@{@"自定义控件":@[@"Image",
                                               @"使用相机|相册",
                                               @"TZImagePickerControllerDemoVC(相册浏览器)",
                                               @"随着TextView输入改变cell高度",
                                               @"Table上添加CollectionView",
                                               @"特殊输入框",
                                               @"指纹解锁",
                                               @"摇一摇",
                                               @"二维码|条形码的生成",
                                               @"二维码的生成扫描及条形码的扫描",
                                               @"可复制文本的Lab",
                                               @"Runtime学习",
                                               @"正则表达式练习",
                                               @"绘制",
                                               @"链式编程"
                                               ]}];
//    [_resourceDataMuAry addObject:@{@"绘制":@[
//                                            @"",
//                                            ]}];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _resourceDataMuAry.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray * rowAry    =   [[_resourceDataMuAry[section] allValues] firstObject];
    return rowAry.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray * rowAry    =   [[_resourceDataMuAry[indexPath.section] allValues] firstObject];
    
    UITableViewCell * cell  =   [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    cell.textLabel.text =   rowAry[indexPath.row];
    
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[_resourceDataMuAry[section] allKeys] firstObject];
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray * rowAry    =   [[_resourceDataMuAry[indexPath.section] allValues] firstObject];
    NSLog(@"%@",rowAry[indexPath.row]);
    NSString * infoStr  =   rowAry[indexPath.row];
    if ([infoStr isEqualToString:@"获取系统相关设备码"]) {
        [self.navigationController pushViewController:[RSDeviceInfoVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"AES128加/解密"]){
        [self.navigationController pushViewController:[AES_Base64VC new] animated:YES];
    }else if ([infoStr isEqualToString:@"打电话"]){
        [RSSystemUtit callPhoneNum:@"18240663517"];
    }else if ([infoStr isEqualToString:@"Image"]){
        [self.navigationController pushViewController:[RSImageOperationVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"发短信(跳转到系统短信应用中)"]){
        //方法一，给指定号码发送信息，跳转到系统短信应用中
        [RSSystemUtit sendSMSToPhoneNum:@"10086"];
    }else if ([infoStr isEqualToString:@"发短信(在当前APP中)"]){
        //方法二，给多个指定号码发送指定内容的信息，不跳出当前APP
        [self sendSMS:@"cxll" recipients:@[@"10086"]];
    }else if ([infoStr isEqualToString:@"发邮件(跳转到系统邮件应用中)"]){//http://blog.csdn.net/feixiang_song/article/details/37565361
        
        [RSSystemUtit sendE_MailWithRecipients:@[@"drs@zhthinkjoy.com"] ccRecipients:nil bccRecipients:nil subject:@"测试" body:@"测试测试!"];
    }else if ([infoStr isEqualToString:@"发邮件(在当前APP中)"]){//http://blog.csdn.net/feixiang_song/article/details/37565361
        
        NSMutableArray * attachmentDataMuAry    =   [NSMutableArray array];
        
        UIImage * image =   [UIImage imageNamed:@"106.png"];
        NSData * imageData = UIImagePNGRepresentation(image);
        NSDictionary    * imageDic  =   @{RSSendE_MailAttachmentData:imageData,
                                          RSSendE_MailMimeType:@"image/png",
                                          RSSendE_MailFilename:@"106.png"};
        
        [attachmentDataMuAry addObject:imageDic];
        
        NSString *file  = [[NSBundle mainBundle] pathForResource:@"HC08中文版规格书" ofType:@"pdf"];
                                  //fullBundlePathFromRelativePath:@"HC08中文版规格书.pdf"];
        NSData * pdfData    = [NSData dataWithContentsOfFile:file];
        NSDictionary    * pdfDic  =   @{RSSendE_MailAttachmentData:pdfData,
                                          RSSendE_MailMimeType:@"application/pdf",
                                          RSSendE_MailFilename:@"HC08中文版规格书.pdf"};
        
        [attachmentDataMuAry addObject:pdfDic];
        
        [self sendE_MailWithRecipients:@[@"drs@zhthinkjoy.com"] ccRecipients:nil bccRecipients:nil subject:@"测试" body:@"测试测试!" attachmentDatas:attachmentDataMuAry];
    }else if ([infoStr isEqualToString:@"系统设置界面"]){
        [self.navigationController pushViewController:[RSSystemSettingTableVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"使用相机|相册"]){
        [self.navigationController pushViewController:[RSCameraOrLibraryVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"TZImagePickerControllerDemoVC(相册浏览器)"]){
        [self.navigationController pushViewController:[TZImagePickerControllerDemoVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"随着TextView输入改变cell高度"]){
        [self.navigationController pushViewController:[RSAutolayoutTextViewCellVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"Table上添加CollectionView"]){
        [self.navigationController pushViewController:[RSTableCollectionView new] animated:YES];
    }else if ([infoStr isEqualToString:@"特殊输入框"]){
        [self.navigationController pushViewController:[RSSpecialFieldVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"指纹解锁"]){
        [self.navigationController pushViewController:[RSTouchIDVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"摇一摇"]){
         [self.navigationController pushViewController:[RSShakeVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"二维码|条形码的生成"]){
        [self.navigationController pushViewController:[RSShowQRCode_BarCodeVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"二维码的生成扫描及条形码的扫描"]){
        [self.navigationController pushViewController:[RSAboutSGQRCodeVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"可复制文本的Lab"]){
        [self.navigationController pushViewController:[RSCopeLabVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"Runtime学习"]){
        [self.navigationController pushViewController:[RSRuntimeLrarnTableVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"正则表达式练习"]){
        [self.navigationController pushViewController:[RSPredicateVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"绘制"]){
        [self.navigationController pushViewController:[RSDrawDemoTableVC new] animated:YES];
    }else if ([infoStr isEqualToString:@"链式编程"]){
        [self.navigationController pushViewController:[RSViewController new] animated:YES];
    }
}



/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
